/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controlador;

import comu.Configuracio;
import controlador.autogenerats.AbonatJpaController;
import entity.Abonat;
import entity.Collita;
import entity.Produccio;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author David
 */
public class AbonatControlador extends AbonatJpaController{

    public AbonatControlador() {
        super(Persistence.createEntityManagerFactory(Configuracio.PERSISTANCE_UNIT));
    }
    
    public List<Abonat> findAbonatEntitiesByProduccio(Produccio produccio) {
        EntityManager em = getEntityManager();
        try{
            Query q = em.createNativeQuery("select * from abonat where `produccio_id` LIKE "+ produccio.getId(), Abonat.class);
            Iterator it = q.getResultList().iterator();
            ArrayList<Abonat> llista = new ArrayList<Abonat>();
            while(it.hasNext()){
                llista.add((Abonat) it.next());
            }
            return llista;
        } finally {
            em.close();
        }
    }
}
